/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pearson;


import agorithms.*;
import agorithms.TopNItemBased;
import agorithms.Utils;
import java.io.File;
import java.text.DecimalFormat;
/**
 *
 * @author hsb
 */
public class Exc {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            //name of movielens data set. dataset = {u1,u2,u3,u4,u5};
            String dataset = "";
            int maxNumber = 2000;
            int maxItem = 0;
            int maxUser = 0;
            int numUserItem[] = new int[2];
            float itemUser[][] = new float[maxNumber][maxNumber];
            Utils util = new Utils();
            
            TopNItemBased topN = new TopNItemBased();
            TopNUserBased topNUser = new TopNUserBased();
            Pearson p = new Pearson();
            double eval[] = new double[3];
            
//            p.generatePearsonPredictedRating(dataset);
//            p.computeMSEPearson(dataset);
//            
            
//            
////////            
//              System.out.println("1");
//              topN.generateTopN(dataset);
////              System.out.println("2");
//              topN.computeHitRate(dataset, eval);
//         
            
////            generate top N file
//            topN.generateTopN(dataset);
//            //compute hit rate
//            topN.computeHitRate(dataset, eval);
//              topN.computePrecision(dataset, eval);
            
            double HR = 0;
            double ARHR  = 0;
            double M[][] = new double[maxItem][maxItem];
            int numData = 5;
            int dem = 0;
            double MSE = 0;
            double RMSE  = 0;
            float MAE = 0;
            double avgHR = 0;
            double avgARHR = 0;
            double avgMSE = 0;
            double avgRMSE = 0;
            double avgMAE = 0;
//            int k=20;
            for(int k=10; k<=50; k+=10) {
            System.out.print("--------k-------"+k +"\n");
            for(int i=1; i<= numData; i++)
            {
                dataset = "u1"+i;
//                System.out.print("--------dataset-------"+dataset +"\n");
                topN.generateTopN(dataset, k);
                topN.computeHitRate(dataset, eval);
//                topNUser.generateTopN(dataset);
//                topNUser.computeHitRate(dataset, eval);
//                p.generateCosinePredictedRating(dataset);
//                p.computeMSECosine(dataset, eval);
                HR += eval[0];
                ARHR += eval[1];
                MSE += eval[0];
                RMSE += eval[1];
                MAE += eval[2];
//                break;
            }
            DecimalFormat df = new DecimalFormat("#.###");
            avgHR =  Double.parseDouble(df.format(HR/numData));
            System.out.print("Avarage HR = " + avgHR +"\n");
            avgARHR = Double.parseDouble(df.format(ARHR/numData));
            System.out.print("Avarage ARHR = " + avgARHR +"\n");
            HR = 0;
            ARHR = 0;
           
            }
//            
//            avgMSE = Double.parseDouble(df.format(MSE/numData));
//            System.out.print("Avarage MSE = " + avgMSE +"\n");
//            avgRMSE = Double.parseDouble(df.format(RMSE/numData));
//            System.out.print("Avarage RMSE = " + avgRMSE +"\n");
//            avgMAE = Double.parseDouble(df.format(MAE/numData));
//            System.out.print("Avarage MAE = " + avgMAE +"\n");
            MSE = 0; 
            RMSE = 0;
            MAE = 0;
            
//            
//            File base = new File("src/data/4444.txt");
//            
//            itemUser = util.readFile(itemUser, numUserItem, base);
//            maxUser = numUserItem[0] +1;
//            maxItem = numUserItem[1] +1;
//            for(int i=0; i<5; i++)
//            {
//                File training = new File("src/data/u1" + i + ".base");
//                File testing = new File("src/data/u1" + i +".test");
//                float trainingSet[][] = new float[maxNumber][maxNumber];
//                float testSet[][] = new float[maxNumber][maxNumber];
//                util.splitDataset(trainingSet, testSet, base);
//
//                util.writeFile(trainingSet, training, maxUser, maxItem);
//
//                util.writeFile(testSet, testing, maxUser, maxItem);
//            }
//          
////          generate top N file
//            topN.generateTopN(dataset);
////            //compute hit rate
//            topN.computeHitRate(dataset, eval);
            
            
//              double pearson = p.computeUserBasedPearson(1-1, 5-1, itemUser, maxUser, maxItem);
//              System.out.print(" pearson = " + pearson);
//              pearson = p.computeWeightedSum(1-1, 2-1, itemUser, maxUser, maxItem);
//            System.out.print(p.computeUserBasedPearson(1-1, 2-1, itemUser, maxUser, maxItem));
//            topNUser.topN(itemUser, 1-1, maxUser, maxItem);
//            //p.normalizeRating(itemUser, maxUser, maxItem);
//            p.generateCosinePredictedRating();
//            p.computeMSE();
//            System.out.print(" pearson = " + pearson);
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
